
window.onload = function() {
    clockStart();
    document.getElementById("headPic").src="head1.png"
}

function clockStart() {
    var today = new Date()
    var h = today.getHours()
    var m = today.getMinutes()
    var s = today.getSeconds()
    m=m>9?m:"0"+m;
    h=h>9?h:"0"+h;
    s=s>9?s:"0"+s;
    var headPic=document.getElementById("headPic").getAttribute("src")
    if(headPic=="head1.png"){//如果是男生
        if(h>12) {
           var hb=h-12;
            hb = hb > 9 ? hb : "0" + hb;
            document.getElementById("txt_clock").innerHTML = hb + ":" + m + ":" + s +" pm"
        }else{
            document.getElementById("txt_clock").innerHTML = h + ":" + m + ":" + s +" am"
        }
    }else{//如果是女生
        document.getElementById("txt_clock").innerHTML = h + ":" + m + ":" + s
    }

    t = setTimeout("clockStart()", 500)
}

var counter = 0
function timerStart() {
        document.getElementById("timer_txt").value = counter++;
        T = setTimeout("timerStart()", 1000);
       if(document.getElementById("timer_txt").value==15){
        alert(sex +" "+document.getElementById("txt_clock").innerHTML)
    }
}
var sex="boy"

function changeHeadpic() {
       var headPic= document.getElementById("headPic")
       if(headPic.getAttribute("src")=="head1.png")
       {
           headPic.src="head2.png"
           sex="girl"
       }else{
           headPic.src="head1.png"
           sex="boy"
       }
       alert(document.getElementById("timer_txt").value)
}

function stop() {
    window.clearTimeout(T);//清除定时器
    counter=0;
    document.getElementById("timer_txt").value=0;
}

function pause() {
    window.clearTimeout(T);//清除定时器
}